package com.bt.lms.ui.page.teaching.arrange;

import com.bt.lms.ui.action.teaching.arrange.FinishArrangeBtnAction;
import com.bt.lms.ui.action.teaching.arrange.NoStartTeachingArrangeBtnAction;
import com.bt.lms.ui.action.teaching.arrange.PageProcessTeachingSuperviseBtnAction;
import com.bt.lms.ui.vo.teaching_arrange.TeachingArrangeInfo;
import com.bt.lms.ui.page.sys.style.BtnStyle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

import java.util.ArrayList;
import java.util.List;

/**
 * 实施中的教学安排界面
 */
public class PageProcessTeachingArrangeList extends VBox {

    /**
     * 实施中的教学那排界面长
     */
    private double preWidth = 1280;
    /**
     * 实施中的教学安界面高
     */
    private double preHeight = 800;

    /**
     *列名默认长度
     */
    private double columnPreWidth = 200;

    public PageProcessTeachingArrangeList(){

        this.setPrefSize(preWidth,preHeight);
        this.setPadding(new Insets(5));
        this.setSpacing(20);

        //顶部横向盒子
        HBox topHBox = new HBox();
        initTopHBox(topHBox);
        //三个按钮横向盒子
        HBox threeBtnHBox = new HBox();
        initThreeBtnHBox(threeBtnHBox);
        ///条件搜索区域横向盒子
        HBox searchHBox = new HBox();
        initSearchHBox(searchHBox);

        //表格盒子
        VBox tableVBox = new VBox();
        initTableVBox(tableVBox);
        //页码横向盒子
        HBox pageNumHBox = new HBox();
        initPageNumHBox(pageNumHBox);
        //底部横向盒子
        HBox bottomHBox = new HBox();
        initBottomHBox(bottomHBox);

        ObservableList<Node> children = this.getChildren();
        children.addAll(topHBox,threeBtnHBox,searchHBox,tableVBox,pageNumHBox,bottomHBox);


    }

    /**
     * 底部横向盒子
     * @param bottomHBox
     */
    private void initBottomHBox(HBox bottomHBox) {
        bottomHBox.setAlignment(Pos.CENTER);

    }

    /**
     * 页码横向盒子
     * @param pageNumHBox
     */
    private void initPageNumHBox(HBox pageNumHBox) {
        pageNumHBox.setSpacing(20);
        pageNumHBox.setPadding(new Insets(10));
        pageNumHBox.setAlignment(Pos.CENTER_RIGHT);
        //首页标签
        Label homeLab = new Label("<<首页");
        homeLab.setTextFill(Color.rgb(108,221,83));
        homeLab.setFont(new Font(20));
        //上一页标签
        Label previousPageLab = new Label("<<上一页");
        previousPageLab.setTextFill(Color.rgb(108,221,83));
        previousPageLab.setFont(new Font(20));
        //第一页按钮
        Button onePageBtn = new Button("1");
        onePageBtn.setPrefWidth(27);
        onePageBtn.setPrefHeight(30);
        //第二页按钮
        Button twoPageBtn = new Button("2");
        twoPageBtn.setPrefWidth(27);
        twoPageBtn.setPrefHeight(30);
        //第三页按钮
        Button threePageBtn = new Button("3");
        threePageBtn.setPrefWidth(27);
        threePageBtn.setPrefHeight(30);
        //第四页按钮
        Button fourPageBtn = new Button("4");
        fourPageBtn.setPrefWidth(27);
        fourPageBtn.setPrefHeight(30);
        //下一页标签
        Label nextPageLab = new Label("下一页>>");
        nextPageLab.setFont(new Font(20));
        nextPageLab.setTextFill(Color.rgb(108,221,83));
        //尾页标签
        Label endPageLab = new Label("尾页>>");
        endPageLab.setFont(new Font(20));
        endPageLab.setTextFill(Color.rgb(108,221,83));
        //总记录数条
        Label totalPageLab = new Label("总页数100条");
        totalPageLab.setFont(new Font(20));
        totalPageLab.setTextFill(Color.rgb(255,65,55));
        //条数文本框
        TextField countTF = new TextField();
        countTF.setPrefWidth(100);
        // /10标签
        Label tenLab = new Label("/10");
        tenLab.setFont(new Font(20));
        //GO按钮
        Button goBtn = new Button("GO");
        ObservableList<Node> children = pageNumHBox.getChildren();
        children.addAll(homeLab,previousPageLab,onePageBtn,twoPageBtn,threePageBtn,fourPageBtn,nextPageLab,endPageLab,totalPageLab,countTF,tenLab,goBtn);
    }

    /**
     * 表格盒子
     * @param tableVBox
     */
    private void initTableVBox(VBox tableVBox) {
        //表格
        TableView tableView = new TableView<>();

        TableColumn serialNumColumn = new TableColumn<>("序号");
        serialNumColumn.setPrefWidth(columnPreWidth);
        TableColumn courseNameColumn = new TableColumn<>("课程名称");
        courseNameColumn.setPrefWidth(columnPreWidth);
        TableColumn courseUnitColumn = new TableColumn<>("所属学习单位");
        courseUnitColumn.setPrefWidth(columnPreWidth);
        TableColumn levelColumn = new TableColumn<>("适用层次");
        levelColumn.setPrefWidth(columnPreWidth);


        TableColumn courseTeacherColumn = new TableColumn<>("授课教师");
        courseTeacherColumn.setPrefWidth(columnPreWidth);
        TableColumn startCourseTimeColumn = new TableColumn<>("开课时间");
        startCourseTimeColumn.setPrefWidth(columnPreWidth);
        TableColumn finishCourseTimeColumn = new TableColumn<>("结课时间");
        finishCourseTimeColumn.setPrefWidth(columnPreWidth);


        //操作列盒子1
        HBox hBox1 = new HBox();
        //教学监管按钮
        Button teachingSuperviseBtn1 = new Button("教学监管");
        //确认课程完成按钮
        Button finishCourseBtn1 = new Button("确认课程完成");
        hBox1.getChildren().addAll(teachingSuperviseBtn1,finishCourseBtn1);
        //教学监管按钮事件
        PageProcessTeachingSuperviseBtnAction pageProcessTeachingSuperviseBtnAction = new PageProcessTeachingSuperviseBtnAction();
        teachingSuperviseBtn1.setOnAction(pageProcessTeachingSuperviseBtnAction);

        //操作列盒子2
        HBox hBox2 = new HBox();
        //教学监管按钮
        Button teachingSuperviseBtn2 = new Button("教学监管");
        //确认课程完成按钮
        Button finishCourseBtn2 = new Button("确认课程完成");
        hBox2.getChildren().addAll(teachingSuperviseBtn2,finishCourseBtn2);

        //操作列盒子3
        HBox hBox3 = new HBox();
        //教学监管按钮
        Button teachingSuperviseBtn3 = new Button("教学监管");
        //确认课程完成按钮
        Button finishCourseBtn3 = new Button("确认课程完成");
        hBox3.getChildren().addAll(teachingSuperviseBtn3,finishCourseBtn3);



        //模拟表中数据
        TeachingArrangeInfo teachingArrangeInfo1 = new TeachingArrangeInfo("1","教育心里学","西南大学","免费师范生","学位专业课","必修","张老师","2012-09-10","2012-10-10","50",hBox1);
        TeachingArrangeInfo teachingArrangeInfo2 = new TeachingArrangeInfo("2","数学","北京师范大学","免费师范生","基础专业课","必修","王老师","2012-10-20","2012-11-20","50",hBox2);
        TeachingArrangeInfo teachingArrangeInfo3 = new TeachingArrangeInfo("3","物理","济南大学","免费师范生","物理课","必修","李老师","2013-01-10","2013-02-10","50",hBox3);
        //数据集合
        List<TeachingArrangeInfo>teachingArrangeInfoList = new ArrayList<>();
        teachingArrangeInfoList.add(teachingArrangeInfo1);
        teachingArrangeInfoList.add(teachingArrangeInfo2);
        teachingArrangeInfoList.add(teachingArrangeInfo3);
        //将数据集合转换成Javafx组件集合
        ObservableList<TeachingArrangeInfo>teachingArrangeInfos = FXCollections.observableArrayList(teachingArrangeInfoList);
        tableView.setItems(teachingArrangeInfos);
        //映射到表中
        serialNumColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo,String>("serialNum"));
        courseNameColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo,String>("courseName"));
        courseUnitColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo,String>("courseUnit"));
        levelColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo,String>("level"));

        courseTeacherColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo,String>("courseTeacher"));
        startCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo,String>("startCourseTime"));
        finishCourseTimeColumn.setCellValueFactory(new PropertyValueFactory<TeachingArrangeInfo,String>("finishCourseTime"));


        tableVBox.getChildren().add(tableView);

        tableView.getColumns().addAll(serialNumColumn,courseNameColumn,courseUnitColumn,levelColumn,courseTeacherColumn,startCourseTimeColumn,finishCourseTimeColumn);
    }



    /**
     * 条件搜索区域横线盒子
     * @param searchHBox
     */
    private void initSearchHBox(HBox searchHBox) {
        //搜索区域横向盒子间距
        searchHBox.setSpacing(15);
        searchHBox.setPadding(new Insets(10));
        //课程单位单位标签
        Label courseUnitLab = new Label("所属学习中心");
        //课程开设单位下拉框
        ComboBox courseUnitCB = new ComboBox<>();
        courseUnitCB.getItems().add("全部");
        courseUnitCB.getItems().add("北京师范大学");
        courseUnitCB.getSelectionModel().selectFirst();

        //适用层次标签
        Label levelLab = new Label("适用层次");
        //适用层次下拉框
        ComboBox levelCB = new ComboBox<>();
        levelCB.getItems().add("全部");
        levelCB.getItems().add("免费师范生");
        levelCB.getItems().add("免费师范生教育硕士");
        levelCB.getItems().add("职后教育");
        levelCB.getItems().add("其他");
        levelCB.getSelectionModel().selectFirst();


        //课程编号/课程名称标签
        Label courseNum = new Label("课程编号/名称");
        ////课程编号/课程名称文本框
        TextField courseNumTF = new TextField();
        courseNumTF.setPromptText("输入课程名称");
        //搜索按钮
        Button searchBtn = new Button("搜索");

        searchHBox.getChildren().addAll(courseUnitLab,courseUnitCB,levelLab,levelCB,courseNum,courseNumTF,searchBtn);
    }

    /**
     * 三个按钮横向盒子
     * @param threeBtnHBox
     */
    private void initThreeBtnHBox(HBox threeBtnHBox) {
        threeBtnHBox.setSpacing(10);
        //未实施的教学安排按钮
        Button noStartBtn = new Button("未实施的教学安排");
        BtnStyle.cancelBtn(noStartBtn);
        NoStartTeachingArrangeBtnAction noStartTeachingArrangeBtnAction = new NoStartTeachingArrangeBtnAction();
        noStartBtn.setOnAction(noStartTeachingArrangeBtnAction);
        noStartBtn.setCursor(Cursor.HAND);
        //实施中的教学安排按钮
        Button processBtn = new Button("实施中的教学安排");
        BtnStyle.cancelBtn(processBtn);
        processBtn.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                processBtn.setCursor(Cursor.HAND);
            }
        });
        //已完成的教学安排按钮
        Button finishBtn = new Button("已完成的教学安排");
        BtnStyle.cancelBtn(finishBtn);
        ObservableList<Node> children = threeBtnHBox.getChildren();
        children.addAll(noStartBtn,processBtn,finishBtn);
        //已完成的教学安排按钮事件
        FinishArrangeBtnAction finishArrangeBtnAction = new FinishArrangeBtnAction();
        finishBtn.setOnAction(finishArrangeBtnAction);
        finishBtn.setCursor(Cursor.HAND);
    }

    /**
     * 顶部横向盒子
     * @param topHBox
     */
    private void initTopHBox(HBox topHBox) {
        topHBox.setSpacing(20);
        topHBox.setPadding(new Insets(2));
        //顶部标签
        Label topLab = new Label("当前位置：🏠>教学管理>教学安排>实施中的教学安排");
        topLab.setFont(new Font(20));//设置字体大小
        ObservableList<Node> children = topHBox.getChildren();
        children.addAll(topLab);
    }
}
